#ifndef __case_async_kenny_kfjiweur89u83r33e3e__
#define __case_async_kenny_kfjiweur89u83r33e3e__

#include <hude/base/log.hpp>
#include <hude/base/async.hpp>

#include "test/test.hpp"

namespace test
{
    using namespace hude;

    //--------------------------------------------------------------------------------
    struct case_async_t : public hude::test::case_t
    {
        //--------------------------------------------------------------------------------
        bool run() override
        {
            size_t ret = 0;

            auto cb_task = [&ret]()
            {
                log_inf( "a task");
                ret += 1;
            };

            auto cb_timer = [&ret]( async_t::id_t, uintptr_t user )
            {
                log_inf( user? "a once timer" : "a cyclicity timer" );
                ret += 1;
            };

            auto async = async_t::get_default_ptr();

            async->add( cb_task );
            async->add( async_t::id(), async_t::emTYPE_SINGLE, async_t::interval_t( 200U ), cb_timer, 1U );

            auto id = async_t::id();
            async->add( id, async_t::emTYPE_CYCLICITY, async_t::interval_t( 500U ), cb_timer );

            std::this_thread::sleep_for( std::chrono::seconds( 3U ) );

            async->remove( id );

            return ret > 6U;
        }
    };

    //--------------------------------------------------------------------------------
    TEST_CASE_ADD( "async", case_async_t, false );

} //namespace test

#endif //__case_async_kenny_kfjiweur89u83r33e3e__